const db = wx.cloud.database()
Page({
    data: {
        category: [
            {name:'果味',id:'guowei'},
            {name:'蔬菜',id:'shucai'},
            {name:'炒货',id:'chaohuo'},
            {name:'点心',id:'dianxin'},
            {name:'粗茶',id:'cucha'},
            {name:'淡饭',id:'danfan'}
        ],
        detail:[],
        curIndex: 0,
        isScroll: false,
        toView: 'guowei',
        cate:"果味"
    },
    onLoad(){
      this.getCategory(this.data.cate)
    },
    // onReady(){
    //     var self = this;
    //      wx.request({
    //          url:'http://www.gdfengshuo.com/api/wx/cate-detail.txt',
    //          success(res){
    //              self.setData({
    //                 detail : res.data
    //             })
    //          }
    //      });
        
    // },
    switchTab(e){
      const self = this;
      this.setData({
        detail:[]
      })
      self.getCategory(e.target.dataset.catename)
      this.setData({
        isScroll: true
      })
      setTimeout(function(){
        self.setData({
          toView: e.target.dataset.id,
          curIndex: e.target.dataset.index,
       
        })
       
      },0)
      setTimeout(function () {
        self.setData({
          isScroll: false
        })
      },1000)
       
    },
    /**获取分类信息 */
    getCategory(catename){
     db.collection("sg_goods").where({category:catename}).get({
          success:(res)=>{
            this.setData({
              detail:res.data
            })
          }
     })
    }
    
})